<template>
  <Card class="role_recharge">
  <div>
      <label>玩家名字:</label>
      <input v-model="userName" placeholder="请输入玩家名字"></input>
      <input v-model="uid"></input>
      <Button type="primary" @click="onSearch">查询</Button>
      <Form  label-position="left" :label-width="80">
        <Form-item label="活动" prop="activeID">
            <Select v-model="activeID" style="width:200px" not-found-text="-1">
              <Option v-for="item in tableList" :value="item.value" :key="item.value">{{ item.label }}</Option>
            </Select>
        </Form-item>
        <Form-item label="玩家ids" prop="uIds">
            <Input v-model="uIds" placeholder="请输入uIds,多个就逗号隔开,-1是全服都发"></Input>
        </Form-item>
        <Form-item label="金币" prop="points">
            <Input v-model="points"  placeholder="请输入金币数量"></Input>
        </Form-item>
        <Form-item label="翡翠" prop="jabe">
            <Input v-model="jabe"  placeholder="请输入翡翠数量"></Input>
        </Form-item>
        <Form-item label="vip经验" prop="vipExp">
            <Input v-model="vipExp"  placeholder="请输入vip经验数量"></Input>
        </Form-item>
        <Form-item label="title" prop="title">
            <Input v-model="title"  placeholder="请输入标题"></Input>
        </Form-item>
        <Form-item label="contents" prop="contents">
            <Input v-model="contents"  placeholder="请输入内容"></Input>
        </Form-item>
        <Button  class="add-group" type="primary" @click="onSendReward">发奖</Button>
      </Form>
  </div>
  </Card>

</template>
<script>
import {sendActiveReward, getRoleBaseInfo} from '@/api/game.js'
import {getVO} from '@/common/proto-vo.js'
export default {
  data () {
    return {
      uIds: '',
      points: '',
      jabe: '',
      vipExp: '',
      activeID: '100004',
      userName: '',
      uid: 0,
      title: '',
      contents: '',
      tableList: [
        {
          value: '100004',
          label: '贴吧活动'
        }
      ]
    }
  },
  created () {
    // console.log('created')
  },
  methods: {
    onSearch () {
      if (this.userName === '') {
        this.$Message.error('userName不能为空!!!')
        return
      }
      console.log('userName:', this.userName)
      getRoleBaseInfo('', this.userName).then((data) => {
        if (!data) {
          return
        }
        this.tableData = []
        let RoleBaseInfoVO = getVO('RoleBaseInfoVO')
        let pv = data.data.data
        let len = pv.data.length
        if (len > 0) {
          let vo = RoleBaseInfoVO.decode(pv.data[0])
          this.uid = vo.id
          console.log(vo)
        }
      })
    },
    onSendReward () {
      if (this.uIds === '') {
        this.$Message.error('uIds不能为空!!!')
        return
      }
      if (this.points === '' && this.jabe === '' && this.vipExp === '') {
        this.$Message.error('不能全都为空!!!')
        return
      }
      let tPoints = 0
      let tJabe = 0
      let tVipExp = 0
      let tActiveId = 0
      if (this.points !== '') {
        tPoints = Number(this.points)
      }
      if (this.jabe !== '') {
        tJabe = Number(this.jabe)
      }
      if (this.vipExp !== '') {
        tVipExp = Number(this.vipExp)
      }

      if (this.activeID !== '') {
        tActiveId = Number(this.activeID)
      }
      console.log('uIds:', this.uIds, ',tActiveId:', tActiveId, ',tPoints:', tPoints, ',tJabe:', tJabe, ',tJabe:', tJabe, ',tVipExp:', tVipExp, ',title:', this.title, ',contents:', this.contents)

      sendActiveReward(this.uIds, tActiveId, tPoints, tJabe, tVipExp, this.title, this.contents).then((data) => {
        if (!data) {
          return
        }
        let ret = data.data.data.intValues[0]
        console.log('sendActiveReward ret:', ret)
        if (ret === 1) {
          this.$Message.info('发送成功!!!')
        } else {
          let msg = '发送失败,errorCode:' + ret
          this.$Message.error(msg)
        }
      })
    }
  },
  computed: {
    // console.log('computed')
  }
}
</script>
<style scoped>
.role_recharge {
  width: 800px;
  height: 500px;
  margin: 60px auto;
}

.add-group{
  float: right;
}
</style>

